package com.admin.system.modules.mnt.entity;

import cn.hutool.core.collection.CollectionUtil;
import com.admin.common.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author sq-lan
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("mnt_deploy")
public class Deploy extends BaseEntity implements Serializable {

    @ApiModelProperty(value = "ID", hidden = true)
    private Integer id;

    @ApiModelProperty(value = "应用编号")
    private Integer appId;


    @TableField(exist = false)
    @ApiModelProperty(name = "服务器", hidden = true)
    private Set<Server> deploys;

    @TableField(exist = false)
    private App app;

    public String getServers() {
        if (CollectionUtil.isNotEmpty(deploys)) {
            return deploys.stream().map(Server::getName).collect(Collectors.joining(","));
        }
        return "";
    }
}
